package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanFixedFragHome;
import com.landeb.shop.huo.bean.ItemFragHomeGridView;

import java.util.List;

/**
 * Created by qiling on 2017/7/27.
 */

public class FixedFragHomeGVAdapter extends BaseAdapter {

    private List<BeanFixedFragHome.DataBean.CatesBean> mList;
    private LayoutInflater mInflater;
    private Context mContext;

    public FixedFragHomeGVAdapter(List<BeanFixedFragHome.DataBean.CatesBean> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
        mInflater=LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {

            convertView = mInflater.inflate(R.layout.item_fraghome_gridview, parent, false);

            holder = new ViewHolder();
            holder.mImageView = (ImageView) convertView.findViewById(R.id.imgV_item_fragHome_gridView);
            holder.mTitle = (TextView) convertView.findViewById(R.id.tv_item_fragHome_gridView);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


// TODO: 2016/10/15 用glide加载图片并赋值给      mImageView
        String picUrl = mList.get(position).getPic();
        String title = mList.get(position).getName();
        holder.mTitle.setText(title);

        Glide.with(mContext)
                .load(picUrl)
                .placeholder(R.drawable.loading_pic)
                .error(R.drawable.error_pic)
                .into(holder.mImageView);
//        /**
//         * 虚拟图片数据
//         * */
//        holder.mImageView.setImageResource(R.mipmap.ic_launcher);

        return convertView;
    }


    private class ViewHolder {
        private ImageView mImageView; //图标
        private TextView mTitle; //文字
    }
}
